package org.red.base;

import java.io.IOException;
import java.io.InputStream;

import org.red.math.Circle;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Rect;

public class Sprite extends Node {

	public Sprite(Bitmap bmp) {
		this._bitmap = bmp;
		_anchorX = _bitmap.getWidth() / 2f;
		_anchorY = _bitmap.getHeight() / 2f;
		_width = _bitmap.getWidth();
		_height = _bitmap.getHeight();
	}
	
	public Sprite(String fileName, Context context) {
		try {
			InputStream is = context.getAssets().open(fileName);
			this._bitmap = BitmapFactory.decodeStream(is);
		} catch (IOException e) {
			e.printStackTrace();
		}
		_anchorX = _bitmap.getWidth() / 2f;
		_anchorY = _bitmap.getHeight() / 2f;
		_width = _bitmap.getWidth();
		_height = _bitmap.getHeight();
	}
	
	@Override
	public void addScale(float x, float y) {
		super.addScale(x, y);
		_anchorX = _bitmap.getWidth() / 2f + _positionX;
		_anchorY = _bitmap.getHeight() / 2f + _positionY;
	}
	
	public Circle getBoundingCircle() {
		return new Circle(_anchorX, _anchorY, _width / 2f);
	}
	
	public Rect getBoundingRect() {
		return new Rect(
			(int)_positionX, (int)_positionY,
			(int)_positionX + _width, (int)_positionY + _height);
	}
}
